<?php

declare(strict_types=1);

/**
 * Author: Jesse
 * Email : jessedev@163.com
 * Date: 2024/6/18 10:36
 * FileName: functions.php
 * DESC: The Relentless Pursuit of Perfection.
 */

use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\Logger\LoggerFactory;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Hyperf\Context\ApplicationContext;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Log\LoggerInterface;
use function Hyperf\Support\env;


if (!function_exists('container')) {
    /**
     * 容器实例.
     *
     * @return ContainerInterface
     */
    function container(): ContainerInterface
    {
        return ApplicationContext::getContainer();
    }
}

if (!function_exists('console_log')) {
    /**
     * 打印控制台日志
     *
     * console_log()->info(json_encode($users));
     */
    function console_log()
    {
        return container()->get(StdoutLoggerInterface::class);
    }
}

if (!function_exists('logger')) {
    /**
     * 打印文件日志.
     *
     * logger()->info(json_encode($users));
     */
    function logger(string $name = null, string $group = 'default'): LoggerInterface
    {
        return container()->get(LoggerFactory::class)->get($name ?? env('APP_NAME'), $group);
    }
}